package com.musifind.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.fizy.client.objects.Album;
import com.musifind.activities.R;
import com.musifind.common.RoundedTransformation;
import com.musifind.models.FavouriteItems;
import com.squareup.picasso.Picasso;

public class FavouriteListAdapter extends ArrayAdapter<FavouriteItems> {

	Context context;
	int layoutResourceId;
	ArrayList<FavouriteItems> objects = new ArrayList<FavouriteItems>();
	FavouriteItems favouriteItems;
	Album album;

	public FavouriteListAdapter(Context context, int layoutResourceId, ArrayList<FavouriteItems> objects) {
		super(context, layoutResourceId, objects);
		this.layoutResourceId = layoutResourceId;
		this.context = context;
		this.objects = objects;
	}

	public static class FavsHolder {
		ImageView imgAlbumCover;
		TextView txtTrackName;
		TextView txtArtistName;
		TextView txtAlbumName;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		View row = convertView;
		FavsHolder holder;

		if (row == null) {

			LayoutInflater inflater = LayoutInflater.from(context);
			row = inflater.inflate(layoutResourceId, parent, false);

			holder = new FavsHolder();
			holder.imgAlbumCover = (ImageView) row.findViewById(R.id.imgAlbumCover);
			holder.txtTrackName = (TextView) row.findViewById(R.id.txtTrackName);
			holder.txtArtistName = (TextView) row.findViewById(R.id.txtArtistName);
			holder.txtAlbumName = (TextView) row.findViewById(R.id.txtAlbumName);
			row.setTag(holder);
		}

		holder = (FavsHolder) row.getTag();

		final FavouriteItems favItems = objects.get(position);

		// holder.imgAlbumCover.setImageBitmap(GeneralHelper.roundCornerImage(
		// GeneralHelper.getBitmapFromURL(favItems.getCoverImage()), 200));
		holder.txtTrackName.setText(favItems.getTrackName());
		holder.txtArtistName.setText(favItems.getArtistName());
		holder.txtAlbumName.setText(favItems.getAlbumName());

		Picasso.with(context).load(favItems.getCoverImage()).transform(new RoundedTransformation(220, 0))
				.into(holder.imgAlbumCover);
		return row;

	}

}
